<?php

class Product extends MY_Controller
{
  public function __construct()
  {
    parent::__construct();
    $this->load->model('product_model');
  }

  public function start()
  {
    $this->drawPage($this->parser->parse('first-product', $this->putTemplateArgs(array()), true));
  }
  
  public function index()
  {
    $this->drawPage($this->parser->parse('product', $this->putTemplateArgs(array()), true));
  }

  public function myproduct()
  {
    $this->drawPage($this->parser->parse('myproduct', $this->putTemplateArgs(array()), true));
  }

  public function myProducts()
  {
    $this->drawPage($this->parser->parse('seller_links', $this->putTemplateArgs(array()), true));
  }

  public function createProductForm()
  {
    $this->drawPage($this->parser->parse('selling', $this->putTemplateArgs(array()), true));
  }
  
  public function createProduct()
  {
    $this->form_validation->set_rules('product_name', 'Product Name', 'required');
//    $this->form_validation->set_rules('product_desc', 'Description', 'required');
    $this->form_validation->set_rules('product_price', 'Price', 'required|is_natural_no_zero');
    if ($this->form_validation->run() == FALSE)
      {
	$this->createProductForm();
      }
    else
      {
	$this->product_model->product_user_id = $this->session->userdata('user_id');
	$this->product_model->product_title = $this->input->post('product_title');
	$this->product_model->product_description = $this->input->post('product_description');
	$this->product_model->product_link = $this->input->post('product_link');
	$this->product_model->product_price = $this->input->post('product_price');
	$this->product_model->product_category_id = 1;
	$this->product_model->product_rate = 1;
	$this->product_model->product_content = 1;
	$this->product_model->insert();
	redirect('/');
      }
    
  } 
 
  public function displayProduct()
  {
    $this->drawPage($this->parser->parse('product', $this->putTemplateArgs(array()), true));
  }
 }